import './index.html';
import dva from 'dva';
import {query} from './services/home';
import * as global from './global';
import {getCurrentMonth,formatNumber,GetRequest,saveAppData} from './utils/tools';
import {appname} from './config';

const app = dva();

app.model(require('./models/home'));
app.model(require('./models/income'));
app.model(require('./models/outlay'));
app.model(require('./models/bank'));
app.model(require('./models/cash'));

let localData = localStorage.getItem(appname);
if(localData)
{
    global.appdata = JSON.parse(localData);
}

global.appdata.wid = GetRequest()['wid'] || 'o3CFSuLx14anxCbypuwd_cG6WE7E';

async function start()
{
    const {data} = await query({
        auth_user: '',
        wid: global.appdata.wid,
        period: '2016-01'
    });
    if(data.result == 'success')
    {
        global.appdata.startTime = data.detail[20].open_date;
        global.appdata.endTime = data.detail[20].last_date;
        global.appdata.selected_month = getCurrentMonth();
    }
    saveAppData();
    app.router(require('./router'));
    app.start('#root');
    saveAppData();
}
start();